<?php
// +----------------------------------------------------------------------
// | Copyright (c) 2023 yoncron All rights reserved.
// +----------------------------------------------------------------------
// | Author: yoncron <yoncron@163.com>
// +----------------------------------------------------------------------
namespace app\queue\redis\crontab;

use app\model\CrontabLogModel;
use app\model\CrontabModel;
use App\service\ExceptionService;
use Webman\RedisQueue\Consumer;

class CrontabQueue implements Consumer
{
    public $queue = 'crontab_queue';
    public $connection = 'crontab';

    public function consume($data){
        $runStatus="正常";
        $log_content='';
        try{
            $log_content = call_user_func($data["callback"]);

        } catch (\Exception $e) {
            ExceptionService::addLog($e);
            $runStatus="异常";
        }
        $endTime = time();
        CrontabLogModel::update(['crontab_log_id'=>$data['crontab_log_id'],'end_time'=>$endTime,'run_status'=>$runStatus,'log_content'=>$log_content]);
        CrontabModel::update(['crontab_id'=>$data['crontab_id'],'last_run_time'=>time()]);
    }
}